#include <cstdio>
#include <cstring>

#define MAXN 1100000
#define _cp(a,b) ((a)<(b))

struct Node
{
    int cnt, time;
    Node( ) { }
    Node( int _cnt, int _time )
        : cnt( _cnt ), time( _time ) { }
};

bool operator < ( const Node &a, const Node &b )
{
    if ( a.cnt < b.cnt )
        return false;
    if ( a.cnt > b.cnt )
        return true;
    return a.time < b.time;
}

typedef Node elem_t;

struct heap{
    elem_t h[MAXN];
    int ind[MAXN],map[MAXN],n,p,c;
    void init(){n=0;}
    void ins(int i,elem_t e){
        for (p=++n;p>1&&_cp(e,h[p>>1]);h[map[ind[p]=ind[p>>1]]=p]=h[p>>1],p>>=1);
        h[map[ind[p]=i]=p]=e;
    }
    int del(int i,elem_t& e){
        i=map[i];if (i<1||i>n) return 0;
        for (e=h[p=i];p>1;h[map[ind[p]=ind[p>>1]]=p]=h[p>>1],p>>=1);
        for (c=2;c<n&&_cp(h[c+=(c<n-1&&_cp(h[c+1],h[c]))],h[n]);h[map[ind[p]=ind[c]]=p]=h[c],p=c,c<<=1);
        h[map[ind[p]=ind[n]]=p]=h[n];n--;return 1;
    }
    int delmin(int& i,elem_t& e){
        if (n<1) return 0;i=ind[1];
        for (e=h[p=1],c=2;c<n&&_cp(h[c+=(c<n-1&&_cp(h[c+1],h[c]))],h[n]);h[map[ind[p]=ind[c]]=p]=h[c],p=c,c<<=1);
        h[map[ind[p]=ind[n]]=p]=h[n];n--;return 1;
    }
};

heap h;
int n, m;
bool visit[ MAXN ];

void work( )
{
    int i, t, k, ans = 0;
    Node p;
    memset( visit, 0, sizeof( visit ) );
    h.init( );
    for ( i = 0; i < m; i++ )
    {
        scanf("%d", &t);
        if ( visit[ t ] )
        {
            h.del( t, p );
            p.cnt++;
            h.ins( t, p );
        }
        else
        {
            if ( h.n < n )
            {
                h.ins( t, Node( 0, i ) );
                visit[ t ] = true;
            }
            else
            {
                h.delmin( k, p );
                visit[ k ] = false;
                ans++;
                h.ins( t, Node( 0, i ) );
                visit[ t ] = true;
            }
        }
    }
    printf("%d\n", ans);
}

int main( )
{
    int cas = 1;
    while ( scanf("%d%d", &n, &m) )
    {
        if ( n == 0 && m == 0 )
            break;
        printf("Case %d: ", cas++);
        work( );
    }
}
